//package com.rparoxysm.tribase.weather;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;

import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;

import java.io.File;
import java.io.IOException;

import org.w3c.dom.Document;
import org.w3c.dom.DOMException;

public class WeatherArchiver {
    static Document document;

    public void parseXml(String filename) {
	DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
	//	factory.setValidating(true);
	//	factory.setNamespaceAware(true);
	
	try {
	    DocumentBuilder builder = factory.newDocumentBuilder();
	    builder.setErrorHandler(new org.xml.sax.ErrorHandler() {
		    // ignore fatal errors (an exception is guaranteed)
		    public void fatalError(SAXParseException exception)
			throws SAXException {
		    }

		    // treat validation errors as fatal
		    public void error(SAXParseException e)
			throws SAXParseException {
			throw e;
		    }

		    // dump warnings too
		    public void warning(SAXParseException err) 
			throws SAXParseException {
			System.out.println("** Warning" +
					   ", line " + err.getLineNumber() +
					   ", uri " + err.getSystemId());
			System.out.println("\t" + err.getMessage());
		    }
		});
	    document = builder.parse(new File(filename));

	} catch (SAXParseException spe) {
	    System.out.println("\n** Parsing error" + 
			       ", line " + spe.getLineNumber() +
			       ", uri " + spe.getSystemId());
	    System.out.println("\t" + spe.getMessage() );
	    
	    Exception x = spe;
	    if(spe.getException() != null) {
		x = spe.getException();
	    }
	    x.printStackTrace();
	} catch (SAXException sxe) {
	    // Error generated during parsing
	    Exception x = sxe;
	    if(sxe.getException() != null) {
		x = sxe.getException();
	    }
	    x.printStackTrace();
	} catch (ParserConfigurationException pce) {
	    // Parser with specified options can't be built
	    pce.printStackTrace();
	} catch (IOException ioe) {
	    // I/O error
	    ioe.printStackTrace();
	}
    }
}
